#pragma once
#ifndef __RTP__
#define __RTP__

#include "util.h"
#ifdef WIN32
#include<vcruntime.h>
#define _CRT_SECURE_NO_WARNINGS 1
#endif


#ifdef __cpluplus
extend "C"{
#endif

#include"tcp_cli.h"

#define Accept 0
#define AcceptEncoding  1
#define AcceptLanguage  2
#define Allow  3
#define Authorization  4
#define Bandwidth 5
#define Blocksize 6
#define CacheControl  7
#define Conference 8
#define Connection 9 
#define ContentBase 10
#define ContentEncoding  11
#define ContentLanguage  12
#define ContentLength 13
#define ContentLocation  14
#define ContentType 15
#define CSeq 16
#define Date 17
#define Expires  19
#define From 20
#define Host 21
#define IfMatch 22
#define IfModifiedSince 23
#define LastModified 24
#define Location 25
#define ProxyAuthenticate 26
#define ProxyRequire 27
#define Public 28
#define Range 29
#define Referer 30
#define RetryAfter 31 
#define Require 32
#define RTPInfo 33
#define Scale 34
#define Speed 35
#define Server 36
#define Session 37
#define Timestamp 38
#define Transport 39
#define Unsupported 40
#define UserAgent 41
#define Vary 42 
#define Via 43 
#define WWWAuthenticate 44

#define BUFF_LEN 1024

#ifdef __cplusplus
extern "C"{
#endif

#ifdef WIN32
#define SPRINTF sprintf_s
#endif
#ifdef linux
#define SPRINTF sprintf
#endif

enum RtspHeader{
	OPTIONS = 0,
	DESCRIBE  = 1,
	SETUP = 2 ,
	TEARDOWN = 3,
	PLAY = 4,
	PAUSE = 5,
	SCALE = 6,
	GET_PARAMETER = 7
};

enum ResponseCode {
	Success = 200,
	Redirection = 300,
	ClientErr = 400 ,
	ServerErr = 500
};

typedef struct _T_MediaResource
{
	char uri[30]; //
	char type[30];
	char time_range[40];
	 struct _T_MediaResource *next;
	/* data */
}MediaResourceList;

typedef struct  _T_RTPCONTEXT{
	unsigned long timestamp;   
	char *m_buffer;   //actual buffer
	enum RtspHeader reqCode;   //code
#ifdef __cplusplus__
	
#endif
	int cSeq;
}RtspReqContext;

typedef struct _T_RTPRESPCONTEXT {
	unsigned long timestamp;
	char m_raw_buff[BUFF_LEN];   //actual buffer
	enum ResponseCode reqCode;   //code
	int cSeq;

}RtspResponse;

typedef struct  _TRtspClient {
	char pAddr[128];
	int port;
	RtspReqContext  m_rtpContext;
	TCPClient m_conn;
	char publicSupport[10][100];
	int iCSeq = 1;   
	MediaResourceList *pMediaResouce;
	int iUdpStartPort = 30000;   
	
}RtspClient;

int  RtspConnect(RtspClient *p ,const char *pAddr, int Port);
void RtspClose(RtspClient *tRtp);
void RtspDo(RtspClient *tRtp, enum RtspHeader code, RtspResponse *p);
int setOptPara(char *ptmp, char *key, char *format,...) ;
int setOpt(char *ptmp,char *key,char *value);
extern char arrHeaderDefine[][128];
extern char arrAction[][32];
#ifdef __cplusplus
}
#endif

#endif